package service.impl.exec;

import entity.Result;
import service.ExecService;

public class StringServiceImpl implements ExecService {
    @Override
    public String exec(String[] data) {
        switch (data[1]){
            case "set":{
                String key=data[2];
                String val=data[3];
                Object o = get(key);
                //存在且不是String类型 不可插入
                if (o!=null&&(!(o instanceof String)))
                    return Result.KeyExist();
                put(key,val);
                return Result.SuccessInsertKey();
            }
            case "get":{
                Object o = get(data[2]);
                if (o==null)
                    return Result.KeyNotExist();
                if (!(o instanceof String))
                    return Result.KeyNotType();
                return (String) o;
            }
        }
        return Result.Error();
    }
}
